package com.smartEdu.controller.web;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smartEdu.commons.LogCvt;
import com.smartEdu.commons.Session;
import com.smartEdu.commons.Tag_Tips;
import com.smartEdu.po.CourseInfoPo;
import com.smartEdu.service.impl.web.WebApiServiceImpl;
import com.smartEdu.utils.JsonUtil;

@Controller
@RequestMapping(value="/web/")
public class WebApiController extends WebBaseController{
	@Autowired
	@Qualifier(value="webApiServiceImpl")
	private WebApiServiceImpl webApiService;
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value="courselist")
	@ResponseBody
	public Object courselist(@RequestParam("academic") String academic, @RequestParam("uid") String uid) {
		List<CourseInfoPo> polist = new ArrayList<CourseInfoPo>();
		CourseInfoPo po = null;
		if(academic == null || "null".equals(academic) || uid == null){
			po = new CourseInfoPo();
			po.setCid("0");
			po.setName("全部");
			polist.add(po);
		}
		else {
			Session sess = new Session();
			sess.put("academic", academic);
			sess.put("uid", uid);
			webApiService.getCourseListApi(sess);
			polist.addAll((List<CourseInfoPo>)sess.geto(Tag_Tips.DAODATA));
		}
		return JsonUtil.toJson(polist);
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value="classlist")
	@ResponseBody
	public Object classlist(@RequestParam("academic") String academic,@RequestParam("cid") String cid, @RequestParam("uid") String uid) {
		List<CourseInfoPo> polist = new ArrayList<CourseInfoPo>();
		CourseInfoPo po = null;
		if(cid == null || "null".equals(cid) || uid == null){
			po = new CourseInfoPo();
			po.setCid("0");
			po.setName("全部");
			polist.add(po);
		}
		else {
			Session sess = new Session();
			sess.put("academic", academic);
			sess.put("cid", cid);
			sess.put("uid", uid);
			webApiService.getClassListApi(sess);
			polist.addAll((List<CourseInfoPo>)sess.geto(Tag_Tips.DAODATA));
		}
		return JsonUtil.toJson(polist);
	}
}
